//
//  ZYNTableViewCellForRecommendSong.m
//  VideoPic
//
//  Created by dllo on 16/3/23.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ZYNTableViewCellForRecommendSong.h"
#import "ZYNCollectionViewCellForRecommendSong.h"
#import "ZYNModelForHotSongs.h"
#import "NetworkingHandle.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height
@interface ZYNTableViewCellForRecommendSong()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collection;
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, strong) NSMutableArray *arrForSongs;
@property (nonatomic, strong) ZYNModelForHotSongs *model;
@end
@implementation ZYNTableViewCellForRecommendSong
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self.arrForSongs = [NSMutableArray array];
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    
    return self;
    
}

- (void)createSubViews {
    
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = CGSizeMake((WIDTH - 40) / 3, (WIDTH - 40) / 3);
    self.flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 10, WIDTH, HEIGHT) collectionViewLayout:self.flowLayout];
    self.flowLayout.minimumInteritemSpacing = 10;
    self.flowLayout.minimumLineSpacing = 50;
    [self.contentView addSubview:self.collection];

    self.collection.delegate = self;
    self.collection.dataSource = self;
    self.collection.backgroundColor = [UIColor whiteColor];
//    self.collection.scrollEnabled = NO;
    
    
    [self.collection registerClass:[ZYNCollectionViewCellForRecommendSong class] forCellWithReuseIdentifier:@"poolForCollection"];
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.collection.frame = self.contentView.frame;
    self.flowLayout.itemSize = CGSizeMake((WIDTH - 40) / 3, (WIDTH - 40) / 3);

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.arrForSongs.count;
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ZYNCollectionViewCellForRecommendSong *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolForCollection" forIndexPath:indexPath];
    ZYNModelForHotSongs *model = [self.arrForSongs objectAtIndex:indexPath.row];
    [cell passModel:model];
    return cell;
}
- (void)passArray:(NSMutableArray *)array {
    
    self.arrForSongs = array;
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    [self.delegate handleDidClick:self.arrForSongs[indexPath.row]];

    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
